<!-- 公司名片 公司简介 -->
<template>
  <div class='company_server'>
    <dt-modal-edit ref='edit' :title='title' :alwaysTip='!isView' :label-width='160' okText='保存'
    :width='70' @ok='onOk' :showOk='!isView' :cancelText="isView?'关闭':'取消'">
      <div class="title_display_status">
        <Checkbox v-model="info.titleDisplayStatus" :disabled='isView'>
          <span class="title_display_status_label">不展示标题</span></Checkbox>
      </div>
      <div class="tips" slot="bottom" v-if="!isView">
        Tips：<br/>
        （1）仅能上传1张图片，内容大小不超过10M；<br/>
        （2）内容建议高度341像素，宽度不限；
      </div>
    </dt-modal-edit>
  </div>
</template>

<script>
  import companyApi from '@/biz/backStage/companyCard'
  import toolMgr from '@/biz/base/tool.js'
  import dtEditor from '@/components/dt/editor/index.vue'
  import editOpt from '../opt/serverEditOpt'
  export default {
    components:{dtEditor},
    data() {
      return {
        info:{},
        loading:false,
        title:'',
        isView:false,
        flag:''
      };
    },
    methods: {
      show(data){
        this.title = data.title
        this.isView = data.isView
        this.flag = data.flag
        if(data.flag=='edit'||data.flag=='view'){
          this.info = data
          this.info.titleDisplayStatus = data.titleDisplayStatus==1?false:true
        }else{
          this.info={
            serviceTitle:'',
            serviceContent:'',
            picUrl:'',
            titleDisplayStatus:false
          }
        }
        this.info.picUrl = this.info.picUrl ? [{
          name: '0',
          url: data.picUrl?data.picUrl:''
        }] : []
        this.$refs.edit.show(editOpt.options(this),this.info)
      },
      hide() {
        this.$refs.edit.hide()
      },
      onOk(data) {
        console.log('提交',data);
        this.loading = true
        let params = {
          id: this.flag == 'add' ? '' : data.id,
          companyId: this.$route.query.companyId,
          serviceTitle: data.serviceTitle,
          serviceContent: data.serviceContent,
          picUrl: data.picUrl.length>0?data.picUrl[0].url:'',
          titleDisplayStatus: data.titleDisplayStatus?2:1
        }
        if(this.flag == 'add'){
          companyApi.companyServiceCreate(params).then(res=>{
            this.$emit('success')
            this.$Message.success('新增成功')
            this.hide()
          })
        }else if(this.flag == 'edit'){
          companyApi.companyServiceUpdate(params).then(res=>{
            this.$emit('success')
            this.$Message.success('修改成功')
            this.hide()
          })
        }
        
        
        
      },
    },
    mounted() {
    },
  }
</script>
<style lang='scss' scoped>
  .company_server {
    padding: 15px;
    position: relative;
  }
  .tips{
    font-size:14px;
    color:#999;
    line-height: 1.8;
    margin-left: 160px
  }
  .title_display_status{
    position: absolute;
    right: 80px;
    top: 70px;
    .title_display_status_label{
      margin-left: 5px;
    }
  }
</style>